package cn.danger.com.presenter;

import android.content.Context;

import cn.danger.com.model.action.ModifyEmailModel;
import cn.danger.com.model.action.ModifyEmailModelImpl;
import cn.danger.com.model.listener.OnCommonListener;
import cn.danger.com.util.Constants;
import cn.danger.com.util.FileCacheService;
import cn.danger.com.view.CommonView;

/**
 * Created by 俊 on 2016/12/29.
 */
public class ModifyEmailPresenterImpl implements ModifyEmailPresenter {

    private Context context;
    private CommonView view;
    private ModifyEmailModel model;

    public ModifyEmailPresenterImpl(Context context, CommonView view) {
        this.context = context;
        this.view = view;
        model = new ModifyEmailModelImpl(context);
    }

    @Override
    public void updateEmail(final String email) {
        view.showDialog();
        model.updateEmail(email, new OnCommonListener() {
            @Override
            public void onSuccess(String message) {
                new FileCacheService(context).updateEmail(email);
                view.hideDialog();
                view.showMessage(Constants.SUCCESS_TO_UPDATE_EMAIL);
            }

            @Override
            public void onError(String error) {
                view.hideDialog();
                view.showMessage(error);
            }
        });
    }
}
